package dao;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate3.HibernateCallback;

import bean.User;

public class Dao extends AbstractDao {

	//this.getHibernateTemplate().get()获得的相当于session.get.可能会遇到延迟加载的问题
	//
	public User getUser(String name, String ps) {
		String sql = "from User where name=1  ";
		List list = null;
		list = this.getHibernateTemplate().find(sql);
		if (list.isEmpty()) {
			return null;
		} else {
			 return (User) list.get(0);
		}
	}
	
	 
	public void getUserCount(){ 
		 this.getHibernateTemplate().execute(new HibernateCallback(){
			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				
				return null;
			}
		 });
	}
	
	 
	public void getUsers(){
	      Session session = this.getSession(); 
	      this.releaseSession(session); 
	}
	
	
	public void getUsers2(){
	      Session session = this.getSession();  
	      Transaction ts = null;
			try{
				ts = session.beginTransaction();
				ts.commit();
			}catch(Exception e){
				if(ts!=null)ts.rollback();
				e.printStackTrace();
			}finally{
				 this.releaseSession(session); 
			}
	     
	       
	}
   
}
